]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
extensions-tool: Add 'reset' command
authorFlorian Müllner <fmuellner@gnome.org>
Wed, 24 Jul 2019 13:18:59 +0000 (15:18 +0200)
committerFlorian Müllner <fmuellner@gnome.org>
Wed, 21 Aug 2019 16:28:02 +0000 (18:28 +0200)
Now that we allow to disable session mode extensions, it can be useful
to reset an extension to its original state, that is disabled in the
regular session, but possibly enabled via the session mode.

Add a corresponding command.

https://gitlab.gnome.org/GNOME/gnome-shell/issues/1234

src/extensions-tool/command-reset.c [new file with mode: 0644]
src/extensions-tool/commands.h
src/extensions-tool/completion/bash/gnome-extensions
src/extensions-tool/main.c
src/extensions-tool/man/gnome-extensions.txt
src/extensions-tool/meson.build

diff --git a/src/extensions-tool/command-reset.c b/src/extensions-tool/command-reset.c
new file mode 100644 (file)
index 0000000..32b5fba
--- /dev/null
@@ -0,0 +1,84 @@
+/* command-reset.c
+ *
+ * Copyright 2019 Florian Müllner <fmuellner@gnome.org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#include <glib/gi18n.h>
+#include <gio/gio.h>
+
+#include "commands.h"
+#include "common.h"
+#include "config.h"
+
+static gboolean
+reset_extension (const char *uuid)
+{
+  g_autoptr(GSettings) settings = get_shell_settings();
+
+  if (settings == NULL)
+    return FALSE;
+
+  return settings_list_remove (settings, "enabled-extensions", uuid) &&
+         settings_list_remove (settings, "disabled-extensions", uuid);
+}
+
+int
+handle_reset (int argc, char *argv[], gboolean do_help)
+{
+  g_autoptr (GOptionContext) context = NULL;
+  g_autoptr (GError) error = NULL;
+  g_auto(GStrv) uuids = NULL;
+  GOptionEntry entries[] = {
+    { .long_name = G_OPTION_REMAINING,
+      .arg_description = "UUID",
+      .arg = G_OPTION_ARG_STRING_ARRAY, .arg_data = &uuids },
+    { NULL }
+  };
+
+  g_set_prgname ("gnome-extensions reset");
+
+  context = g_option_context_new (NULL);
+  g_option_context_set_help_enabled (context, FALSE);
+  g_option_context_set_summary (context, _("Reset an extension"));
+  g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
+
+  if (do_help)
+    {
+      show_help (context, NULL);
+      return 0;
+    }
+
+  if (!g_option_context_parse (context, &argc, &argv, &error))
+    {
+      show_help (context, error->message);
+      return 1;
+    }
+
+  if (uuids == NULL)
+    {
+      show_help (context, _("No UUID given"));
+      return 1;
+    }
+  else if (g_strv_length (uuids) > 1)
+    {
+      show_help (context, _("More than one UUID given"));
+      return 1;
+    }
+
+  return reset_extension (*uuids) ? 0 : 2;
+}
index e8c05eec3b4bf5b3243ce0d0b86ccda15a7e903e..618e8413da919c4ca1d3d0bda346888521546d85 100644 (file)
@@ -26,6 +26,7 @@ G_BEGIN_DECLS
 
 int handle_enable     (int argc, char *argv[], gboolean do_help);
 int handle_disable    (int argc, char *argv[], gboolean do_help);
+int handle_reset      (int argc, char *argv[], gboolean do_help);
 int handle_list       (int argc, char *argv[], gboolean do_help);
 int handle_info       (int argc, char *argv[], gboolean do_help);
 int handle_prefs      (int argc, char *argv[], gboolean do_help);
index 56bda405f52be2d22c7b46d5411c43db88a260c7..9630ce9d77272d1e8c87bc95124cebca98e1274b 100644 (file)
@@ -5,7 +5,7 @@
 ################################################################################
 
 __gnome_extensions() {
-  local commands="version enable disable info install show list create pack prefs uninstall"
+  local commands="version enable disable reset info install show list create pack prefs uninstall"
   local COMMAND=${COMP_WORDS[1]}
 
   _init_completion -s || return
@@ -35,7 +35,7 @@ __gnome_extensions() {
         uninstall)
           local list_opt=--user
           ;;&
-        enable|disable|info|show|prefs|uninstall)
+        enable|disable|info|show|prefs|reset|uninstall)
           COMPREPLY=($(compgen -W "`gnome-extensions list $list_opt`" -- "$2"))
           return 0
           ;;
index 96117a90d3d75fe3691fb2aefb0f12a612631ce4..dafca212358271279223c1aae632c4f528d198ff 100644 (file)
@@ -244,6 +244,7 @@ usage (void)
   g_printerr ("  version   %s\n", _("Print version"));
   g_printerr ("  enable    %s\n", _("Enable extension"));
   g_printerr ("  disable   %s\n", _("Disable extension"));
+  g_printerr ("  reset     %s\n", _("Reset extension"));
   g_printerr ("  uninstall %s\n", _("Uninstall extension"));
   g_printerr ("  list      %s\n", _("List extensions"));
   g_printerr ("  info      %s\n", _("Show extension info"));
@@ -309,6 +310,8 @@ main (int argc, char *argv[])
     return handle_enable (argc, argv, do_help);
   else if (g_str_equal (command, "disable"))
     return handle_disable (argc, argv, do_help);
+  else if (g_str_equal (command, "reset"))
+    return handle_reset (argc, argv, do_help);
   else if (g_str_equal (command, "list"))
     return handle_list (argc, argv, do_help);
   else if (g_str_equal (command, "info"))
index db768582a423873cb48ca7e015b76e9bec793470..c04b37174c499d1a6d406d75cd580663d7f3e2c1 100644 (file)
@@ -19,6 +19,8 @@ SYNOPSIS
 
 *gnome-extensions* disable 'UUID'
 
+*gnome-extensions* reset 'UUID'
+
 *gnome-extensions* info 'UUID'
 
 *gnome-extensions* show 'UUID'
@@ -62,6 +64,12 @@ Disables the extension identified by 'UUID'.
 +
 If the extension is not enabled, the command will do nothing.
 
+*reset* 'UUID'::
+Reset the extension identified by 'UUID'.
++
+The extension will be disabled in GNOME, but may be enabled by other sessions
+like GNOME Classic.
+
 *info* 'UUID'::
 Show details of the extension identified by 'UUID', including name,
 description and state.
index ae646c28c23c9c84278b207790fa62ecb652d060..25d5118ef6c5d48cf7c4c310b8030896313bda22 100644 (file)
@@ -17,6 +17,7 @@ sources = [
   'command-list.c',
   'command-pack.c',
   'command-prefs.c',
+  'command-reset.c',
   'command-uninstall.c',
   'main.c'
 ]